package com.rgbgame.editor;

/**
 * 
 */

class Viewport{
	/**
	 * 
	 */

	public Vector2d center;  //point of focus of camera
	public float scaling;    //higher scaling parameter means we are more zoomed in

	public Viewport(){
		center = new Vector2d(rgbEditor.pApplet.width/2.0f, rgbEditor.pApplet.height/2.0f);
		scaling = 1.0f;
	}

	public Viewport(Vector2d c, float s){
		center = c;
		scaling = s;
		if (scaling < .001f){scaling = .001f;}
	}

	public Vector2d worldToScreen(Vector2d world){
		float x1 = scaling*(world.x - center.x) + rgbEditor.pApplet.width/2.0f;
		float y1 = scaling*(world.y - center.y) + rgbEditor.pApplet.height/2.0f;
		return new Vector2d(x1,y1);
	}

	public Vector2d screenToWorld(Vector2d scr){
		float x1 = (scr.x - rgbEditor.pApplet.width/2.0f)/scaling + center.x;
		float y1 = (scr.y - rgbEditor.pApplet.height/2.0f)/scaling + center.y;
		return new Vector2d(x1,y1);
	}

	public void nudge(Vector2d nudgeVec){
		//Nudges the camera by a certain amount in world coordinates.
		center.x += nudgeVec.x; center.y += nudgeVec.y;
	}

	public void scaledNudge(Vector2d nudgeVec){
		//Nudges the camera by a certain amount in screen coordinates.
		//This is probably more useful for UI motions, since it takes the
		//zoom factor into account.
		center.x += nudgeVec.x/scaling; center.y += nudgeVec.y/scaling;
	}

	public void nudgeZoom(float _nudge){
		scaling *= 1.0f+_nudge;
		if (scaling < .001f){scaling = .001f;}
		if (scaling > 1000){scaling = 1000;}
	}

	public void easeTo(Vector2d easeVec, float easeSpeed){
		center.x = (1.0f-easeSpeed)*center.x + easeSpeed*easeVec.x;
		center.y = (1.0f-easeSpeed)*center.y + easeSpeed*easeVec.y;
	}

}